package com.itxiuyixiu.contoller;

import com.itxiuyixiu.service.QiniuyunService;
import com.itxiuyixiu.tools.util.returns.ReturnVo;
import org.apache.ibatis.annotations.Delete;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author 黄磊
 * @date 2020/5/21
 */
@RestController
public class QiniuyunController {

    @Autowired
    private QiniuyunService qiniuyunService;

    @PostMapping("/photo")
    public ReturnVo getUploadPhotoToken() {
        return ReturnVo.getSuccessReturn(qiniuyunService.getUploadPhotoToken());
    }

    @DeleteMapping("/photo")
    public ReturnVo deleteFile(@RequestParam String key) {
        switch (qiniuyunService.deleteFile(key)) {
            case 0: return ReturnVo.getSuccessReturn("成功删除文件");
            case 1: return ReturnVo.getFailureReturn("删除的文件不属于您");
            case 2: return ReturnVo.getFailureReturn("删除文件失败，可能文件已经被删除");
            default:return ReturnVo.getFailureReturn("系统发生未知错误");
        }
    }
}
